package com.zzty.txj1.controller;

import com.zzty.txj1.entity.Event;
import com.zzty.txj1.entity.UserEvents;
import com.zzty.txj1.service.UserEventsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/UserEvents")
public class UserEventsController {
    private static final Logger logger = LoggerFactory.getLogger(UserEventsController.class);

    @Autowired
    UserEventsService userEventsService;

    @RequestMapping(value = "/addUserEvents", method = RequestMethod.POST)
    public Integer addUserEvents(UserEvents userEvents) {
        logger.info("UserEvents--controller ============ addUserEvents");

        Integer flag;
        UserEvents userEvents1 = userEventsService.getUserEventsByUserId(userEvents);
        if (userEvents1 == null) {
            flag = userEventsService.addUserEvents(userEvents);
        } else {
            flag = userEventsService.updateUserEvents(userEvents);
        }
        return flag;
    }

    @RequestMapping("/getAllUserEvents")
    public List getAllUserEvents() {
        logger.info("UserEvents--controller ============ getAllUserEvents");

        List<UserEvents> userEvents = userEventsService.getAllUserEvents();
        return userEvents;
    }

    @RequestMapping("/getUserEventsByUserId")
    public UserEvents getUserEventsByUserId(UserEvents userEvents) {
        logger.info("UserEvents--controller ============ getUserEventsByUserId");

        UserEvents userEvents1 = userEventsService.getUserEventsByUserId(userEvents);
        return userEvents1;
    }

    @RequestMapping("/getUserEventsById")
    public UserEvents getUserEventsById(UserEvents userEvents) {
        logger.info("UserEvents--controller ============ getUserEventsById");

        UserEvents userEvents1 = userEventsService.getUserEventsById(userEvents);
        return userEvents1;
    }

    @RequestMapping(value = "/deleteUsereventsById", method = RequestMethod.POST)
    public Integer deleteUsereventsById(UserEvents userEvents) {
        logger.info("UserEvents--controller ============ deleteUsereventsById");

        Integer count = userEventsService.deleteUsereventsById(userEvents);
        return count;
    }

    @RequestMapping(value = "/updateUserEventsById", method = RequestMethod.POST)
    public Integer updateUserEventsById(UserEvents userEvents) {
        logger.info("UserEvents--controller ============ updateUserEventsById");

        Integer count = userEventsService.updateUserEventsById(userEvents);
        return count;
    }

}
